package com.dinadi.yidi.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.dinadi.yidi.R;

import java.io.File;
import java.util.ArrayList;

/**
 * author: JiaYu.He
 * Date: 2017/10/19
 * Time: 15:04
 */

public class RefundRequestGridAdapter extends BaseAdapter {
    private ArrayList<String> listUrls;
    Context mContext;
    int columnWidth;

    public RefundRequestGridAdapter(Context context, ArrayList<String> listUrls) {
        this.listUrls = listUrls;
        this.mContext = context;
    }

    public void clearDate() {
        listUrls.clear();
    }

    @Override
    public int getCount() {
        //   return listUrls.size();
        if (listUrls.size() == 6) {
            return 6;
        }
        return (listUrls.size() + 1);
    }

    @Override
    public String getItem(int position) {
        return listUrls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.adapter_refund_request_img, null);
            imageView = (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(imageView);
        } else {
            imageView = (ImageView) convertView.getTag();
        }
        if (position == listUrls.size()) {
            Glide.with(mContext)
                    .load(R.drawable.icon_refund_photo)
                    .placeholder(R.mipmap.default_error)
                    .error(R.mipmap.default_error)
                    .centerCrop()
                    .crossFade()
                    .into(imageView);
            if (position == 6) {
                imageView.setVisibility(View.GONE);
            }
        } else {
            Glide.with(mContext)
                    .load(new File(getItem(position)))
                    .placeholder(R.mipmap.default_error)
                    .error(R.mipmap.default_error)
                    .centerCrop()
                    .crossFade()
                    .into(imageView);
        }
        return convertView;
    }
}
